package com.wayin.lift.controller.check;

import java.util.Arrays;
import java.util.List;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.wayin.lift.entity.PersonnelEntity;
import com.wayin.lift.service.PersonnelService;
import com.wayin.common.utils.*;

import static org.springframework.web.bind.annotation.RequestMethod.GET;
import static org.springframework.web.bind.annotation.RequestMethod.POST;
import static org.springframework.web.bind.annotation.RequestMethod.PUT;

/**
 * 人员表
 *
 * @author HYXK
 * @email null@qq.com
 * @date 2020-05-26 09:56:38
 */
@Api(tags = "人员表接口")
@RestController
@RequestMapping("/personnel")
public class PersonnelController {

    @Autowired
    private PersonnelService personnelService;

    /**
     * 列表
     */
    @ApiOperation("查找所有人员表信息")
    @RequestMapping(value = "/list", method = GET)
    public R list(){
        List<PersonnelEntity> page = personnelService.findAllPersonnel();

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @ApiOperation("根据{pId}查找人员表信息")
    @RequestMapping(value = "/info/{pId}", method = GET)
    public R info(@PathVariable("pId") Long pId){
		PersonnelEntity personnel = personnelService.getById(pId);

        return R.ok().put("personnel", personnel);
    }

    /**
     * 保存
     */
    @ApiOperation("添加人员表信息")
    @RequestMapping(value = "/save", method = POST)
    public R save(@RequestBody PersonnelEntity personnel){
		personnelService.save(personnel);

        return R.ok();
    }

    /**
     * 修改
     */
    @ApiOperation("修改人员表信息")
    @RequestMapping(value = "/update", method = POST)
    public R update(@RequestBody PersonnelEntity personnel){

        return personnelService.update(personnel) ? R.ok() : R.error();
    }

    /**
     * 删除
     */
    @ApiOperation("删除人员表信息")
    @RequestMapping(value = "/delete", method = PUT)
    public R delete(@RequestParam Long[] pIds){

        return personnelService.removeByIds(Arrays.asList(pIds)) ? R.ok() : R.error();
    }

}
